﻿/*
 * Created by SharpDevelop.
 * User: v.i.evgenyev
 * Date: 08.11.2011
 * Time: 17:20
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.Configuration;



namespace TinyCAT
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
//----------------Open file for translation----------------
		void ToolStripButton1Click(object sender, EventArgs e)
		{
			if (openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				myAPP.setting.fName = openFileDialog1.FileName;
				richTextBox1.LoadFile(myAPP.setting.fName);
				MainForm.ActiveForm.Text = "TinyCAT - " + myAPP.setting.fName;
			}
		}
//-----------setting-------------------------------------		
		void ToolStripButton2Click(object sender, EventArgs e)
		{
			Setting FormSetting = new Setting();
			FormSetting.ShowDialog();
			toolStripStatusLabel2.Text = myAPP.setting.LangFrom + " -> " + myAPP.setting.LangTo;
			toolStripStatusLabel3.Text = "Coincidence: " + myAPP.setting.Coincidence.ToString();
		}
//----------------Save file------------------------
		void ToolStripButton3Click(object sender, EventArgs e)
		{
			richTextBox1.SaveFile(myAPP.setting.fName);
		}
		void ContextMenuStrip1Opening(object sender, System.ComponentModel.CancelEventArgs e)
		{
			
		}
//----------translate selection--------------------		
		void ToolStripMenuItem1Click(object sender, EventArgs e)
		{
			myAPP.textToTranslate.Value = richTextBox1.SelectedText;
			Color curColor = richTextBox1.SelectionColor;
			richTextBox1.SelectionColor = Color.Red;
			Form1 Formtranslate = new Form1();
			Formtranslate.ShowDialog();
			richTextBox1.SelectionColor = curColor;
			richTextBox1.SelectedText = myAPP.TranslatedText.Value;
		}
//----------open database translations------------------------
		void ToolStripButton4Click(object sender, EventArgs e)
		{
			if (openFileDialog2.ShowDialog() == DialogResult.OK)
			{
				myAPP.setting.tmdbName = openFileDialog2.FileName;
				toolStripStatusLabel1.Text = "Database TM: " + myAPP.setting.tmdbName;
				try
				{
					System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
					AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
					appSettings.Settings["tmdbName"].Value = myAPP.setting.tmdbName;
					config.Save();
				}
				catch
				{
					MessageBox.Show ("err!");
				}
			}
		}
//-------About-------------------------------------------			
		
		void ToolStripButton5Click(object sender, EventArgs e)
		{
			Assembly assem = Assembly.GetEntryAssembly();
			AssemblyName assemName = assem.GetName();
			Version ver = assemName.Version;
			string info = "TinyCAT";
			string info2 = "ver. " + ver.ToString();
			MessageBox.Show (info2, info);
			
		}
//---------Load program-----------------------------------		
		void MainFormShown(object sender, EventArgs e)
		{
			myAPP.start_app_config();
			toolStripStatusLabel1.Text = "Database TM: " + myAPP.setting.tmdbName;
			toolStripStatusLabel2.Text = myAPP.setting.LangFrom + " -> " + myAPP.setting.LangTo;
			toolStripStatusLabel3.Text = "Coincidence: " + myAPP.setting.Coincidence.ToString();
		}
		
		void MainFormFormClosing(object sender, FormClosingEventArgs e)
		{
			myAPP.save_app_config();
		}
//---------Undo--------------------------------------------		
		void ToolStripButton6Click(object sender, EventArgs e)
		{
			 if(richTextBox1.CanUndo == true)
    		{
       			// Undo the last operation.
       			richTextBox1.Undo();
       			// Clear the undo buffer to prevent last action from being redone.
       			richTextBox1.ClearUndo();
    		}
		}
		
//---------Redo--------------------------------------------				
		void ToolStripButton7Click(object sender, EventArgs e)
		{
		if(richTextBox1.CanRedo == true)
			{
				richTextBox1.Redo();
			}	
		}
	}
}